package wicket.example.utils;

import org.apache.wicket.util.lang.Objects;

public final class SimpleSelectableObject<T> implements ISelectable<T> {

	private T object;
	private boolean selected = false;

	public SimpleSelectableObject(T object, boolean selected) {
		this.setObject(object);
		this.setSelected(selected);
	}

	public final T getObject() {
		return object;
	}

	public final void setObject(T object) {
		this.object = object;
	}

	public final boolean isSelected() {
		return selected;
	}

	public final void setSelected(boolean selected) {
		this.selected = selected;
	}

	@Override
	public int hashCode() {
		return object.hashCode() ^ 37 / (selected ? 7 : 13);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (!(obj instanceof SimpleSelectableObject)) {
			return false;
		}
		SimpleSelectableObject object = (SimpleSelectableObject) obj;
		return Objects.equal(object.selected, this.selected)
				&& Objects.equal(object.object, this.object);
	}

}
